<?php
require $_SERVER['DOCUMENT_ROOT'].'/../_core/common.php';

$msg = array();

//权限验证
if( Role::init() == false ){
	$msg['error'] = false;
	$msg['string'] = '权限不足！';
	$myjson = json_encode($msg); 
	echo $myjson; 
	exit;
}

$db = new DB('news');

$title_id = isset($_POST['title_id']) ? h($_POST['title_id']) : '';

if($title_id==''){//id不存在
	$msg['error'] = false;
	$msg['string'] = '参数有误！';
}else{
	$time = time();
	$news_sql = 'select category_id,title_history_id,title from news where title_id="'.$title_id.'"';
	$news_rs = $db->query($news_sql)->getOne();
	
	$data=array('is_publish'=>2,
				'publish_time'=>$time,
				'title_history_id'=>($news_rs['title_history_id']+1),
				'edit_uid'=>Sessions::get('uid'),
				'updated'=>$time
				);
	$db->table('news')->where('title_id="'.$title_id.'"')->update($data)->run();
	
	//记录动作日志
	Log::logs_articles($news_rs['category_id'], 10, $title_id, $news_rs['title']);

	$msg['string'] = date('Y-m-d H:i:s',$time);
	$msg['error'] = true;
}
$myjson = json_encode($msg); 
echo $myjson; 
exit;